function canConstruct(ransomNote, magazine) {
  let ransomNoteArr = [...ransomNote];
  let magazineArr = [...magazine];
  let result = true;

  for (let i = 0; i < ransomNoteArr.length; i++) {
    let idx = magazineArr.indexOf(ransomNoteArr[i]);
    if (idx >= 0) {
      magazineArr.splice(idx, 1);
    } else {
      result = false;
      break;
    }
  }

  console.log("true");
  return result;
}

let ransomNote = "aa";
let magazine = "aab";
canConstruct(ransomNote, magazine);
